home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / async1.zip / ASYNC.ASM next >
Assembly Source File  |  1985-09-13  |  26KB  |  546 lines

  1.  
  2.         Page    60,132
  3.         .Radix  16
  4.         Title   Communications Interface Routine
  5.         Subttl  Macros
  6.         Page
  7. Save    Macro   R1,R2,R3,R4,R5,R6,R7,R8,R9,R10
  8.         Irp     Rx,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10> ;Repeat for each parm
  9.         Ifnb    <Rx>                            ;If this parm not blank
  10.         Push    Rx                              ;Save the register
  11.         Endif                                   ;End Ifnb
  12.         Endm                                    ;End Irp
  13.  
  14.  
  15. ;;      The Restore macro makes use of the fact that R1-R10 are still defined,
  16. ;;      but, being a different macro, this will not expand when the Save macro
  17. ;;      is used.  Note that the Restore macro will restore whatever registers
  18. ;;      were last Save'd in the assembly listing, not during execution.
  19. ;;      Therefore, its use is restricted to restoring the previous sequential
  20. ;;      Save macro's registers.
  21.  
  22. Restore Macro
  23.         Irp     Rx,<R10,R9,R8,R7,R6,R5,R4,R3,R2,R1> ;Repeat for each parm
  24.         Ifnb    <Rx>                      ;If this parm not blank
  25.         Pop     Rx                        ;Pop the register
  26.         Endif                             ;End Ifnb
  27.         Endm                              ;End Irp
  28.         Endm                              ;End of Restore macro
  29.         Endm                              ;End of Save Macro
  30.  
  31. Setint  Macro   Vector,Routine            ;Sets an interrupt vector
  32.         Lea     DX,Routine                ;Address the routine
  33.         Mov     AX,25*100+Vector          ;Set the vector
  34.         Int     21                        ;Call DOS to do it
  35.         Endm
  36.  
  37. Incbuf  Macro   Buffer
  38.         Local   Notend                    ;Not at end of buffer label
  39.  
  40. ;;      Macro to increment the buffer pointer.  This macro is used
  41. ;;      internally by other buffer processing macros.  The pointer to
  42. ;;      be incremented must be in BX.  Results in BX.
  43.  
  44.         Inc     BX                        ;Point at next character
  45.         Cmp     BX,Offset Buffer.Buff + Length Buff ;At end of buffer?
  46.         Jb      Notend                    ;No - continue
  47.         Lea     BX,Buffer.Buff            ;Point back to start of buffer
  48.  
  49. Notend  Label   Near                      ;Not at end of buffer
  50.         Endm                              ;End of macro
  51.  
  52. Bufinit Macro   Buffer                    ;Initialize the buffers
  53.  
  54. ;;      This macro must be called once for each buffer.  It's purpose
  55. ;;      is to ensure the pointers are set up correctly before the
  56. ;;      buffers are used.  Unless the buffers are initialized, the
  57. ;;      results will be unpredictable.
  58.  
  59.         Lea     BX,Buffer.Buff            ;Get address of buffer
  60.         Mov     Buffer.Staptr,BX          ;Set start of data address
  61.         Mov     Buffer.Endptr,BX          ;End of data too (buffer empty)
  62.         Endm                              ;End of macro
  63.  
  64. Putbuf  Macro   Buffer                    ;Insert a character in the buffer
  65.         Local   Bufull
  66.  
  67. ;;      This macro puts a byte into BUFFER.  Origin is AL, and it uses the
  68. ;;      BX reg.  The carry flag is set if the buffer is full and the routine
  69. ;;      cannot place a bit in the buffer, and is cleared if the character is
  70. ;;      inserted in the buffer and pointers updated.
  71. ;;      The buffer must have been defined with the BUFFER structure.
  72.  
  73.         Mov     BX,Buffer.Endptr          ;Get pointer to end of buffer
  74.         Incbuf  Buffer                    ;Point at next character
  75.         Cmp     BX,Buffer.Staptr          ;Buffer full?
  76.         Je      Bufull                    ;Yes - buffer overrun
  77.         Mov     [BX],AL                   ;Store a byte
  78.         Mov     Buffer.Endptr,BX          ;Replace new pointer
  79.         Stc                               ;Inverse of carry flag returned
  80.  
  81. Bufull  Label   Near                      ;Get a character from the buffer
  82.         Cmc                               ;Invert carry bit for return code
  83.         Endm                              ;End of macro
  84.  
  85. Getbuf  Macro   Buffer                    ;Get a character from the buffer
  86.         Local   Bufemp
  87.  
  88. ;;      This macro gets a character from BUFFER and returns it in AL.  It
  89. ;;      uses the BX reg.  Carry flag is set if the buffer is empty, and
  90. ;;      cleared if a character is returned in AL.
  91. ;;      The buffer must have been defined with the BUFFER structure.
  92.  
  93.         Mov     BX,Buffer.Staptr          ;Get buffer data start
  94.         Cmp     BX,Buffer.Endptr          ;Any data in buffer?
  95.         Je      Bufemp                    ;Yes - go transmit it
  96.         Incbuf  Buffer                    ;Point at next character
  97.         Mov     AL,[BX]                   ;Get a byte
  98.         Mov     Buffer.Staptr,BX          ;Restore pointer
  99.         Stc                               ;Set complement of carry flag
  100.  
  101. Bufemp  Label   Near
  102.         Cmc                               ;Set true return flag
  103.         Endm
  104.  
  105. Flush   Macro   Buffer                    ;Flush the buffer
  106.  
  107. ;;      This macro will flush BUFFER by setting the start and end
  108. ;;      pointers equal.  It uses the BX reg.
  109.  
  110.         Mov     BX,Buffer.Staptr          ;Get start of data
  111.         Mov     Buffer.Endptr,BX          ;Set end = start (empty)
  112.         Endm
  113.  
  114. ;       Structure used for buffer definition.
  115. ;       Staptr = Endptr means buffer is full.  Otherwise buffer has data
  116. ;       in it.
  117.  
  118.  
  119. Buffer  Struc
  120. Buff    Db      256d Dup (0)              ;Buffer size in decimal
  121. Staptr  Dw      0                         ;Start of data pointer
  122. Endptr  Dw      0                         ;End of data pointer
  123. Buffer  Ends
  124.  
  125. Inital  Record  Speed:3, Parity:2, Stop:1, Len:2 ;Init call parms in AL
  126.  
  127.         Subttl  Equates
  128.         Page
  129.  
  130. ;               Line status bits -- AH
  131. Timeout Equ     80                        ;Time out error
  132. Tbufemp Equ     40                        ;Transmit buffer empty
  133. Tbufnfl Equ     20                        ;Transmit buffer not full
  134. Brkdet  Equ     10                        ;Break detect
  135. Framerr Equ     08                        ;Framing error
  136. Parerr  Equ     04                        ;Parity error
  137. Rcveovr Equ     02                        ;Receive buffer overrun
  138. Rdatrdy Equ     01                        ;Receive buffer has data
  139.  
  140. ;               Modem status bits -- AL
  141. Rlsd    Equ     80                        ;Received line signal detect
  142. Ri      Equ     40                        ;Ring indicator
  143. Dsr     Equ     20                        ;Data set ready
  144. Cts     Equ     10                        ;Clear to send
  145. Drlds   Equ     08                        ;Delta receive line signal detect
  146. Teri    Equ     04                        ;Trailing edge ring indicator
  147. Ddsr    Equ     02                        ;Delta data set ready
  148. Dcts    Equ     01                        ;Delta clear to send
  149.  
  150. ;               Interrupt Enable reg bit definitions
  151. Msint   Equ     08                        ;Modem status int bit
  152. Rlsint  Equ     04                        ;Receive line status int bit
  153. Thrint  Equ     02                        ;Transmit holding reg empty int bit
  154. Daint   Equ     01                        ;Data availalbe interrupt
  155.  
  156. ;               Modem Control Port
  157.  
  158. Out2    Equ     08                        ;Out2 bit
  159. Out1    Equ     04                        ;Out1 bit
  160. Rts     Equ     02                        ;Request to Send
  161. Dtr     Equ     01                        ;Data Terminal Ready
  162.  
  163. ;       Other equates and records
  164. Asysmsk Equ     10                        ;System interrupt (port 21) mask
  165. Perror  Equ     -1                        ;Paramater error
  166. Baseadr Equ     3F8                       ;Comm port 1 base address
  167.  
  168.         Subttl  Constants
  169.         Page    +
  170. Comm    Segment Para Public 'Code'
  171.         Assume CS:Comm ,DS:Comm ,ES:nothing ,SS:Nothing
  172.  
  173.         Org     100h                      ;Set starting point
  174. Entry   Label   Near                      ;Initialization entry point
  175.         Jmp     Start                     ;Go to initialization code
  176.  
  177.         Db      'Asynchronous Communications Port Driver '
  178.